<template>
	<view style="overflow: hidden;">
		<u-tabs name="cate_name" count="cate_count" :list="list" :is-scroll="false" :active-color="active" :current="current" @change="change"></u-tabs>
		
		<view v-if="current==0" class="content_list">
			<view class="list" v-for="(item,index) in company.report" :key='index' @click="add(item)"
			:class="{'content_list_last':index== 1}">
				<view class="content_text">
					<view class="content_arr">
						<text>企业名称:</text>
						<text>{{item.enterprise_name}}</text>
					</view>
					<view class="content_arr">
						<text>所属年度:</text>
						<text>{{item.year}}</text>
					</view>
					<view class="content_arr">
						<text>所属季度:</text>
						<text>{{dictValue.season[item.season]}}</text>
					</view>
					<view class="content_arr">
						<text>经营状态:</text>
						<text>{{dictValue.businessstatus[item.status]}}</text>
					</view>
				</view>
				<view class="content-title">
					<view class="oprt-box">
						<view class="box">
							<img @tap.stop="add(item, 'edit')" class="btn-oprt" src="../../static/edit.png" />							
							<img @tap.stop="del(item)" class="btn-oprt" style="margin-top:5px;" src="../../static/delete.png" />
						</view>
					</view>		
				</view>
			</view>
			<view v-if="company.report.length==0" style="text-align: center;line-height:40px;">
				<label>没有相关记录</label>
			</view>
		</view>
		
		<view v-if="current==1" class="content_list">
			<view class="list" v-for="(item,index) in company.safe" :key='index' @click="add(item)"
			:class="{'content_list_last':index== 1}">
				<view class="content_text">
					<view class="content_arr">
						<text>队伍名称:</text>
						<text>{{item.name}}</text>
					</view>
					<view class="content_arr">
						<text>队伍人数:</text>
						<text>{{item.num}}</text>
					</view>
					<view class="content_arr">
						<text>成立时间:</text>
						<text>{{item.found_date}}</text>
					</view>
					<view class="content_arr">
						<text>备注:</text>
						<text>{{item.remark}}</text>
					</view>
				</view>
				<view class="content-title">
					<view class="oprt-box">
						<view class="box">
							<img @tap.stop="add(item, 'edit')" class="btn-oprt" src="../../static/edit.png" />							
							<img @tap.stop="del(item)" class="btn-oprt" style="margin-top:5px;" src="../../static/delete.png" />
						</view>
					</view>		
				</view>
			</view>
			<view v-if="company.safe.length==0" style="text-align: center;line-height:40px;">
				<label>没有相关记录</label>
			</view>
		</view>
		
		
		<view class="content_add">
			<u-button v-if="current==0" type="primary" @click="add(0)" :custom-style="customStyle" hover-class="button-hover">添加企业经营情况
			</u-button>
		</view>
		<view class="content_add">
			<u-button v-if="current==1" type="primary" @click="add(0)" :custom-style="customStyle" hover-class="button-hover">添加安全应急队伍及设施设备
			</u-button>
		</view>
	</view>
</template>

<script>
	import common from '../../common/common.js'
	export default {
		data() {
			return {
				dictValue: common.dictValue,
				enterprise_id: null,
				company:{},
				list: [{
					cate_name: '企业经营情况'
				}, {
					cate_name: '安全应急队伍及设施设备'
				}],
				current: 0,
				active:'#68B92E',
				customStyle: {
					backgroundColor: '#68B92E'
				},
			}
		},
		onLoad(options){
			console.log(options)			
			console.log(options.id);
			this.enterprise_id = options.id;
			this.getCompany(options.id);
		},
		methods: {
			del(item){
				console.log(item);
				var that = this;
				var url;
				switch(this.current){
					case 0:
						url = that.$common.baseUrl + 'api/data/deleteCompanyReport';
					    break;
					case 1:
						url = that.$common.baseUrl + 'api/data/deleteCompanySafe';
					    break;
				}
				uni.showModal({
				    title: '提示',
				    content: '确定要删除该条数据?',
				    success: function (res) {
						
				        if (res.confirm) {
							var cookie =  uni.getStorageSync('cookie');
							uni.request({
								url: url,
								data: {enterprise_id: item.enterprise_id, id: item.id},
								header: {'content-type': 'application/x-www-form-urlencoded','cookie':cookie},		
								method: 'POST',
								success: res => {
									that.getCompany(that.enterprise_id);
								},
								fail: err => {
									uni.hideLoading();
								}
							})
							
							
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			getCompany(company_id) {
				var that = this;
				uni.showLoading({"title":"数据加载中..."});
				uni.request({
					url: this.$common.baseUrl + 'api/data/getCompany',
					data: {company_id: company_id},
					method: 'GET',
					success: res => {
						uni.hideLoading();
						console.log(res.data.data)
						that.company = res.data.data;
					},
					fail: err => {
						uni.hideLoading();
					}
				})
			},
			change(index) {
				this.current = index;
			},
			add(item, t) {
				item = encodeURIComponent(JSON.stringify(item));
				switch(this.current){
				    case 0:
						uni.navigateTo({
							url:'/pages_A/enterprise/business?enterprise_id='+this.enterprise_id+'&t='+t+'&item='+item
						})
				        break;
					case 1:
						uni.navigateTo({
							url:'/pages_A/enterprise/security?enterprise_id='+this.enterprise_id+'&t='+t+'&item='+item
						})
						break;
				    default:
						uni.navigateTo({
							url:'/pages_A/enterprise/business?enterprise_id='+this.enterprise_id+'&t='+t+'&item='+item
						})
				        break;
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #F5F5F5
	}
</style>
<style scoped>
	.content {
		width: 100%;
		margin-top: 0 !important;
		background-color: #F5F5F5;
		padding: 0 30rpx 20rpx 30rpx !important;
	}

	.content_serch {
		position: sticky;
		top: 0;
		padding-top: 20rpx;
	}

	.content_list {
		width: 95%;
		margin: 20rpx auto;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.content_list_last {
		margin-bottom: 110rpx;
	}

	/* .content-book:not(:nth-last-of-type(2)) */
	/* .content_list:last-of-type(){
		margin-bottom: 60rpx !important;
	} */	
	.list {
		margin-top:20rpx;
		padding: 30rpx;
		display: flex;
		flex-direction: row;
		background-color: #FFFFFF;
	}

	.content_title {
		display: flex;
		justify-content: space-between;
		margin-bottom: 10rpx;
	}

	.content_name {
		font-size: 27rpx;
		letter-spacing: 2rpx;
		font-weight: bold;
	}

	.content_text {
		margin-right: 50rpx;
		flex:1;
	}
	
	.content_arr {
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
		letter-spacing: 2rpx;
		margin-bottom: 5rpx;
	}

	.right image {
		width: 30rpx;
		height: 30rpx;
	}

	.content_add {
		position: fixed;
		bottom: 5rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 95%;
	}

	.button-hover {
		background-color: #68B92E;
	}
	.oprt-box{display: flex;justify-content:center;align-items: center;height:100%;}
	.btn-oprt{width:14px;height:14px;display:flex;}
</style>

